﻿// <copyright file="admin_CreateNewAction.aspx.cs" company="NTalent">
// Copyright (c) 2010, NTalent, Inc. All rights reserved
// </copyright>
// <author>卢俊坤</author>
// <author>王彦博 符茂松</author>

using System;
using Net.Ntalent.Action50.Core.Controls;
using Net.Ntalent.Action50.Core.Util;
using Net.Ntalent.Action50.Core.Dao;
using Net.Ntalent.Action50.Core.Service;
using Net.Ntalent.Action50.DataAccess;

/// <summary>
/// 管理页面，新建一个action
/// </summary>
///<author>王彦博</author> 
/// <copyright>
/// Copyright (c) 2010, NTalent, Co. Ltd. All rights reserved.
/// </copyright>
/// <version>1.0.0</version>
public partial class admin_CreateNewAction : PageBase
{
    public admin_CreateNewAction()
    {
        //设置权限，使未登录用户不能访问该页
        authentication = Constants.AUTHENTICATION_ADMIN;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    /// <summary>
    /// 进行新建操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LinkButton1_Click(object sender, EventArgs e)
    {

        ActionDao actionDao = new ActionDao();

        //从页面提取信息
        string actionName = HTMLFilter.Strip(tb_Name.Text.Trim());
        long member = Convert.ToInt64(tb_Members.Text.Trim());
        string aboutOurTeam = Helper.FiltScriptAndStyle(FCKeditor1.Value);
        string aboutOurAction = HTMLFilter.Strip(ScroLeft.Text.Trim());

        //创建T_Action实体
        T_ACTIONS action = new T_ACTIONS();
        action.SHORT_INTRO = aboutOurAction;
        action.TEAMS_INTRO = aboutOurTeam;
        action.EFFECT_PEOPLE_COUNT = member;
        action.ACTION_NAME = actionName;

        try
        {
            actionDao.Create(action);
        }
        catch
        {
            //弹出提示，创建失败
            Message.Text = "Create Action Failed!";
            popupCmd.Text =
                "<script type='text/javascript'>$('.popup').css('display', 'block');$('#alpha').css('display', 'block');</script>";
        }

        //弹出提示，已创建成功
        Message.Text = "Create Action Successfully!";
        popupCmd.Text = "<script type='text/javascript'>$('.popup').css('display', 'block');$('#alpha').css('display', 'block');</script>";
    }

    /// <summary>
    /// Logout
    /// </summary>
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        AuthenticationService authenticationService = new AuthenticationService();
        authenticationService.LogOut();
        Response.Redirect(Request.UrlReferrer.ToString());
    }
}
